def solve(intervals: list[tuple[int, int]]):
    intervals.sort(key=lambda x :x[1])
    count = 0
    last_end_time = -float('inf')
    for start,end in intervals:
        if start >= last_end_time:
            last_end_time = end
            count += 1
        
    return count

if __name__ == "__main__":
    n = int(input())
    intervals = []
    for _ in range(n):
        start, end = map(int, input().split())
        intervals.append((start, end))
    print(solve(intervals))
